import request from '/@/utils/request';
import { useUrlUtil } from '/@/utils/urlUtil';
import { BaseRequest, BaseResponse } from '/@/interfaces/BaseModel';
import { DatabaseInfoApi } from '/@/enums/dpp-api-enum';
import {
    DatabaseInfoSearchParamModel,
    DatabaseInfoListModel,
    DatabaseInfoDetailModel,
    DatabaseInfoAddParamModel,
    DatabaseInfoEditParamModel,
    DatabaseInfoDeleteParamModel
} from '/@/interfaces/DataPipelineModel';

function useDatabaseInfo() {
    return {
        list: function (payload: BaseRequest<DatabaseInfoSearchParamModel>) {
            return request.post<BaseResponse<DatabaseInfoListModel[]>>(DatabaseInfoApi.LIST, payload);
        },
        detail: function (payload: Object) {
            const useUrl = useUrlUtil();
            return request.get<BaseResponse<DatabaseInfoDetailModel>>(useUrl.joinParam(DatabaseInfoApi.DETAIL, payload));
        },
        add: function (payload: BaseRequest<DatabaseInfoAddParamModel>) {
            return request.post<BaseResponse<boolean>>(DatabaseInfoApi.ADD, payload);
        },
        edit: function (payload: BaseRequest<DatabaseInfoEditParamModel>) {
            return request.post<BaseResponse<boolean>>(DatabaseInfoApi.EDIT, payload);
        },
        del: function (payload: BaseRequest<DatabaseInfoDeleteParamModel>) {
            return request.post<BaseResponse<boolean>>(DatabaseInfoApi.DEL, payload);
        },
    };
}

export default useDatabaseInfo;